<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

function smarty_cms_function_flvplayer($params, &$smarty) {
    $dir = "song";
    $width = "360";
    $height = "288";
    $flv_selfA = explode('/', $_SERVER["PHP_SELF"]);
    $flv_self = $flv_selfA[sizeOf($flv_selfA)-1] . '?page=' . $_GET['page'];
    
    if(!empty($params['dir']))
        $dir = $params['dir'];
    if(!empty($params['width']))
        $width = $params['width'];
    if(!empty($params['height']))
        $height = $params['height'];
        
    $flv_dir = "uploads/".$dir;
// autoscanning the flv directory
@$flv_d = dir($flv_dir);
if ($flv_d) { 
    while($flv_entry=$flv_d->read()) {  
        $flv_entry = preg_replace("/ /","%20",$flv_entry);
        $flv_pos = strpos(strtolower($flv_entry), ".flv");
        if (!($flv_pos === false)) {  
        $flv_files[] = $flv_entry; 
        } 
    }
    $flv_d->close();
}


// getting the file from the url
if ($_GET['file']) { $flv_file = $_GET['file']; } else { $flv_file = 1; }

// extracting the name of the video
$flv_p1 = strpos($flv_files[$flv_file-1],"/");
$flv_p2 = strpos($flv_files[$flv_file-1],".flv");
$flv_name = substr($flv_files[$flv_file-1],$flv_p1,($flv_p2-$flv_p1));

// Showed in content

    $result .= '<h1>'.$flv_name.'</h1><br />'."\n";
    $result .= '<div id="flvplayer">'."\n";
    $result .= '<object type="application/x-shockwave-flash" data="'.$flv_dir.'/flvplayer.swf?file='.$flv_files[$flv_file-1].'" width="'.$width.'" height="'.$height.'" wmode="transparent">'."\n";
    $result .= '<param name="movie" value="'.$flv_dir.'/flvplayer.swf?file='.$flv_files[$flv_file-1].'" />'."\n";
    $result .= '<param name="wmode" value="transparent" />'."\n";
      $result .= '</object>'."\n";
    $result .= '</div>'."\n";
      $result .= '<div id="flvarray">'."\n";
    $result .= '<ul>'."\n";
    for ($flv_i=0; $flv_i<=sizeof($flv_files)-1; $flv_i++) {
        $flv_p1 = strpos($flv_files[$flv_i],"/");
        $flv_p2 = strpos($flv_files[$flv_i],".flv");
        $flv_name = substr($flv_files[$flv_i],$flv_p1,($flv_p2-$flv_p1));
    $result .= '<li><a href="'.$flv_self.'&file='.($flv_i+1).'">'.$flv_name.'</a></li>'."\n";
        }
    $result .= '</ul>'."\n";
    $result .= '</div>'."\n";

    return $result;
}


function smarty_cms_help_function_flvplayer()
{
  ?>
  <h3>IMPORTANT !!!</h3>
  <p>the flvplayer.swf file must be stored in the directory with .flv files</p>
  <p>you have to download it from <a href="http://www.jeroenwijering.com/?item=Flash_Video_Player">here</a> (with .fla sources)</p>
  <p>This script is licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">Creative Commons License </a>by his original <a href="mailto:mail@jeroenwijering.com">author</a></p>
  <h3>What does this do?</h3>
  <p>Creates an flv (flash video) player with automatic listing of stored files</p>
  <h3>How do I use it?</h3>
  <p>Just insert the tag into your template/page like: <code>{flvplayer}</code><em> (Can it be more simple ?)</em></p>
  <h3>What parameters does it take?</h3>
  <p>
  <ul>
     <li><em>(optional)</em>  <tt>dir</tt> - path from root/uploads (whitout end "/") where .flv files and flvplayer.swf are stored (default : videos)</li>
     <li><em>(optional)</em>  <tt>width</tt> - Width of the video (default : 360)</li>
     <li><em>(optional)</em>  <tt>height</tt> - Height of the video (default : 288)</li>
  </ul>
  </p>
  <?php
}


function smarty_cms_about_function_flvplayer() 
{
?>
  <p>Author:  chris.. &lt;chris@poegraphie.net&gt;</p>
  <p>Version -buggy- 0.1</p>
<?php
}

?>